﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace DAL
{
    public class AllDAL
    {
        /// <summary>
        /// Log增加一条数据
        /// </summary>
        public int AddLog(Model.SYNC_LOG model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SYNC_LOG(");
            strSql.Append("SYNC_DATE,Name,CONTENT,STATUS)");
            strSql.Append(" values (");
            strSql.Append("@SYNC_DATE,@Name,@CONTENT,@STATUS)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@SYNC_DATE", SqlDbType.DateTime),
					new SqlParameter("@Name", SqlDbType.VarChar,150),
					new SqlParameter("@CONTENT", SqlDbType.VarChar,150),
					new SqlParameter("@STATUS", SqlDbType.VarChar,150)};
            parameters[0].Value = model.SYNC_DATE;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.CONTENT;
            parameters[3].Value = model.STATUS;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }


        /// <summary>
        /// 价格增加一条数据
        /// </summary>
        public int PriceAdd(Model.SAP_PRODUCT_PRICE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_PRODUCT_PRICE(");
            strSql.Append("VKORG,MATNR,MAKTX,KBETR,KPEIN,KMEIN,MSEHS,DATAB,DATBI,ZFLAG,KSCHL,SPART)");
            strSql.Append(" values (");
            strSql.Append("@VKORG,@MATNR,@MAKTX,@KBETR,@KPEIN,@KMEIN,@MSEHS,@DATAB,@DATBI,@ZFLAG,@KSCHL,@SPART)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@VKORG", SqlDbType.Char,4),
					new SqlParameter("@MATNR", SqlDbType.Char,18),
					new SqlParameter("@MAKTX", SqlDbType.Char,40),
					new SqlParameter("@KBETR", SqlDbType.VarChar,50),
					new SqlParameter("@KPEIN", SqlDbType.Decimal,5),
					new SqlParameter("@KMEIN", SqlDbType.VarChar,50),
					new SqlParameter("@MSEHS", SqlDbType.Char,10),
					new SqlParameter("@DATAB", SqlDbType.DateTime),
					new SqlParameter("@DATBI", SqlDbType.DateTime),
					new SqlParameter("@ZFLAG", SqlDbType.Char,1),
					new SqlParameter("@KSCHL", SqlDbType.Char,4),
					new SqlParameter("@SPART", SqlDbType.Char,2)};
            parameters[0].Value = model.VKORG;
            parameters[1].Value = model.MATNR;
            parameters[2].Value = model.MAKTX;
            parameters[3].Value = model.KBETR;
            parameters[4].Value = model.KPEIN;
            parameters[5].Value = model.KMEIN;
            parameters[6].Value = model.MSEHS;
            parameters[7].Value = model.DATAB;
            parameters[8].Value = model.DATBI;
            parameters[9].Value = model.ZFLAG;
            parameters[10].Value = model.KSCHL;
            parameters[11].Value = model.SPART;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 价格临时表增加一条数据
        /// </summary>
        public int PriceTEMPAdd(Model.SAP_PRODUCT_PRICE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_PRODUCT_PRICE_TEMP(");
            strSql.Append("VKORG,MATNR,MAKTX,KBETR,KPEIN,KMEIN,MSEHS,DATAB,DATBI,ZFLAG,KSCHL,SPART)");
            strSql.Append(" values (");
            strSql.Append("@VKORG,@MATNR,@MAKTX,@KBETR,@KPEIN,@KMEIN,@MSEHS,@DATAB,@DATBI,@ZFLAG,@KSCHL,@SPART)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@VKORG", SqlDbType.Char,4),
					new SqlParameter("@MATNR", SqlDbType.Char,18),
					new SqlParameter("@MAKTX", SqlDbType.Char,40),
					new SqlParameter("@KBETR", SqlDbType.VarChar,50),
					new SqlParameter("@KPEIN", SqlDbType.Decimal,5),
					new SqlParameter("@KMEIN", SqlDbType.VarChar,50),
					new SqlParameter("@MSEHS", SqlDbType.Char,10),
					new SqlParameter("@DATAB", SqlDbType.DateTime),
					new SqlParameter("@DATBI", SqlDbType.DateTime),
					new SqlParameter("@ZFLAG", SqlDbType.Char,1),
					new SqlParameter("@KSCHL", SqlDbType.Char,4),
					new SqlParameter("@SPART", SqlDbType.Char,2)};
            parameters[0].Value = model.VKORG;
            parameters[1].Value = model.MATNR;
            parameters[2].Value = model.MAKTX;
            parameters[3].Value = model.KBETR;
            parameters[4].Value = model.KPEIN;
            parameters[5].Value = model.KMEIN;
            parameters[6].Value = model.MSEHS;
            parameters[7].Value = model.DATAB;
            parameters[8].Value = model.DATBI;
            parameters[9].Value = model.ZFLAG;
            parameters[10].Value = model.KSCHL;
            parameters[11].Value = model.SPART;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 价格删除一条数据
        /// </summary>
        public bool PriceDelete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_PRODUCT_PRICE");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 价格临时表删除数据
        /// </summary>
        public bool PriceTEMPDelete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_PRODUCT_PRICE_TEMP");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }




        /// <summary>
        /// 产品增加一条数据
        /// </summary>
        public int ProductAdd(Model.SAP_PRODUCT model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_PRODUCT(");
            strSql.Append("MATNR,MAKTX,MATKL,WGBEZ,SPART,VTEXT,PRODH,PRODH2,PRODH3,UMREZ,ZMEINS,ZMSEHS,MEINS,MSEHS,ZBARCOD,MHDHB,ZSTATUS,VKORG,ZSCAN,TART,MATAT)");
            strSql.Append(" values (");
            strSql.Append("@MATNR,@MAKTX,@MATKL,@WGBEZ,@SPART,@VTEXT,@PRODH,@PRODH2,@PRODH3,@UMREZ,@ZMEINS,@ZMSEHS,@MEINS,@MSEHS,@ZBARCOD,@MHDHB,@ZSTATUS,@VKORG,@ZSCAN,@TART,@MATAT)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@MATNR", SqlDbType.Char,10),
					new SqlParameter("@MAKTX", SqlDbType.Char,40),
					new SqlParameter("@MATKL", SqlDbType.Char,9),
					new SqlParameter("@WGBEZ", SqlDbType.Char,20),
					new SqlParameter("@SPART", SqlDbType.Char,2),
					new SqlParameter("@VTEXT", SqlDbType.Char,20),
					new SqlParameter("@PRODH", SqlDbType.Char,18),
					new SqlParameter("@PRODH2", SqlDbType.Char,18),
					new SqlParameter("@PRODH3", SqlDbType.Char,18),
					new SqlParameter("@UMREZ", SqlDbType.VarChar,100),
					new SqlParameter("@ZMEINS", SqlDbType.VarChar,100),
					new SqlParameter("@ZMSEHS", SqlDbType.Char,10),
					new SqlParameter("@MEINS", SqlDbType.VarChar,10),
					new SqlParameter("@MSEHS", SqlDbType.Char,10),
					new SqlParameter("@ZBARCOD", SqlDbType.Char,10),
					new SqlParameter("@MHDHB", SqlDbType.VarChar,100),
					new SqlParameter("@ZSTATUS", SqlDbType.Char,1),
					new SqlParameter("@VKORG", SqlDbType.Char,4),
					new SqlParameter("@ZSCAN", SqlDbType.Char,1),
					new SqlParameter("@TART", SqlDbType.Char,4),
                    new SqlParameter("@MATAT", SqlDbType.VarChar,500)
                                        };
            parameters[0].Value = model.MATNR;
            parameters[1].Value = model.MAKTX;
            parameters[2].Value = model.MATKL;
            parameters[3].Value = model.WGBEZ;
            parameters[4].Value = model.SPART;
            parameters[5].Value = model.VTEXT;
            parameters[6].Value = model.PRODH;
            parameters[7].Value = model.PRODH2;
            parameters[8].Value = model.PRODH3;
            parameters[9].Value = model.UMREZ;
            parameters[10].Value = model.ZMEINS;
            parameters[11].Value = model.ZMSEHS;
            parameters[12].Value = model.MEINS;
            parameters[13].Value = model.MSEHS;
            parameters[14].Value = model.ZBARCOD;
            parameters[15].Value = model.MHDHB;
            parameters[16].Value = model.ZSTATUS;
            parameters[17].Value = model.VKORG;
            parameters[18].Value = model.ZSCAN;
            parameters[19].Value = model.TART;
            parameters[20].Value = model.MATAT;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 产品删除一条数据
        /// </summary>
        public bool ProductDelete()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_PRODUCT ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 产品临时增加一条数据
        /// </summary>
        public int ProductTEMPAdd(Model.SAP_PRODUCT model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_PRODUCT_TEMP(");
            strSql.Append("MATNR,MAKTX,MATKL,WGBEZ,SPART,VTEXT,PRODH,PRODH2,PRODH3,UMREZ,ZMEINS,ZMSEHS,MEINS,MSEHS,ZBARCOD,MHDHB,ZSTATUS,VKORG,ZSCAN,TART,MATAT)");
            strSql.Append(" values (");
            strSql.Append("@MATNR,@MAKTX,@MATKL,@WGBEZ,@SPART,@VTEXT,@PRODH,@PRODH2,@PRODH3,@UMREZ,@ZMEINS,@ZMSEHS,@MEINS,@MSEHS,@ZBARCOD,@MHDHB,@ZSTATUS,@VKORG,@ZSCAN,@TART,@MATAT)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@MATNR", SqlDbType.Char,10),
					new SqlParameter("@MAKTX", SqlDbType.Char,40),
					new SqlParameter("@MATKL", SqlDbType.Char,9),
					new SqlParameter("@WGBEZ", SqlDbType.Char,20),
					new SqlParameter("@SPART", SqlDbType.Char,2),
					new SqlParameter("@VTEXT", SqlDbType.Char,20),
					new SqlParameter("@PRODH", SqlDbType.Char,18),
					new SqlParameter("@PRODH2", SqlDbType.Char,18),
					new SqlParameter("@PRODH3", SqlDbType.Char,18),
					new SqlParameter("@UMREZ", SqlDbType.VarChar,100),
					new SqlParameter("@ZMEINS", SqlDbType.VarChar,100),
					new SqlParameter("@ZMSEHS", SqlDbType.Char,10),
					new SqlParameter("@MEINS", SqlDbType.VarChar,10),
					new SqlParameter("@MSEHS", SqlDbType.Char,10),
					new SqlParameter("@ZBARCOD", SqlDbType.Char,10),
					new SqlParameter("@MHDHB", SqlDbType.VarChar,100),
					new SqlParameter("@ZSTATUS", SqlDbType.Char,1),
					new SqlParameter("@VKORG", SqlDbType.Char,4),
					new SqlParameter("@ZSCAN", SqlDbType.Char,1),
					new SqlParameter("@TART", SqlDbType.Char,4),
                    new SqlParameter("@MATAT", SqlDbType.VarChar,500)
                                        };
            parameters[0].Value = model.MATNR;
            parameters[1].Value = model.MAKTX;
            parameters[2].Value = model.MATKL;
            parameters[3].Value = model.WGBEZ;
            parameters[4].Value = model.SPART;
            parameters[5].Value = model.VTEXT;
            parameters[6].Value = model.PRODH;
            parameters[7].Value = model.PRODH2;
            parameters[8].Value = model.PRODH3;
            parameters[9].Value = model.UMREZ;
            parameters[10].Value = model.ZMEINS;
            parameters[11].Value = model.ZMSEHS;
            parameters[12].Value = model.MEINS;
            parameters[13].Value = model.MSEHS;
            parameters[14].Value = model.ZBARCOD;
            parameters[15].Value = model.MHDHB;
            parameters[16].Value = model.ZSTATUS;
            parameters[17].Value = model.VKORG;
            parameters[18].Value = model.ZSCAN;
            parameters[19].Value = model.TART;
            parameters[20].Value = model.MATAT;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 产品临时删除一条数据
        /// </summary>
        public bool ProductTEMPDelete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_PRODUCT_TEMP");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 产品对比后添加数据
        /// </summary>
        public bool ProductContrastAdd()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"
INSERT INTO SAP_PRODUCT
                (MATNR, MAKTX, MATKL, WGBEZ, SPART, VTEXT, PRODH, PRODH2, PRODH3, UMREZ, ZMEINS, ZMSEHS, MEINS, 
                MSEHS, ZBARCOD, MHDHB, ZSTATUS, VKORG, ZSCAN, TART, MATAT)
SELECT   MATNR, MAKTX, MATKL, WGBEZ, SPART, VTEXT, PRODH, PRODH2, PRODH3, UMREZ, ZMEINS, ZMSEHS, MEINS, 
                MSEHS, ZBARCOD, MHDHB, ZSTATUS, VKORG, ZSCAN, TART, MATAT
FROM      SAP_PRODUCT_TEMP AS SAP_PRODUCT_TEMP_1
WHERE   (MATNR NOT IN
                    (SELECT   MATNR
                     FROM      SAP_PRODUCT AS SAP_PRODUCT_TEMP))");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 产品对比后更新数据
        /// </summary>
        public bool ProductContrastUpdate()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"UPDATE  SAP_PRODUCT
SET         PRODH = b.PRODH, PRODH2 = b.PRODH2, PRODH3 = b.PRODH3
FROM      SAP_PRODUCT INNER JOIN
                SAP_PRODUCT_TEMP AS b ON SAP_PRODUCT.MATNR = b.MATNR");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }




        /// <summary>
        /// 门店增加一条数据
        /// </summary>
        public int StoreAdd(Model.SAP_STORE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_STORE(");
            strSql.Append("MANDT,VKORG,WERKS,KUNNR,NUM,KUNNR_SH,ZMD_ID,ZMD_MC,ZMD_JC,ZMD_TYPE,ZMD_ATTR,VTWEG,ZMD_UPID,ZKUNNR_SP,ZKUNNR_SH,NAME3,TELF1,MOB_NUMBER,TELFX,SMTP_ADDR,STRAS,POST_CODE1,CITY_CODE,ZDATE_CR,ZSTATUS,ZDATE_DE,ZREC_STA,DATUM,UZEIT,UNAME,DATUM_CR,UZEIT_CR,UNAME_CR,DATUM_QY,FLAG_QY,ZMD_ATTR2,ZCITY_TYPE)");
            strSql.Append(" values (");
            strSql.Append("@MANDT,@VKORG,@WERKS,@KUNNR,@NUM,@KUNNR_SH,@ZMD_ID,@ZMD_MC,@ZMD_JC,@ZMD_TYPE,@ZMD_ATTR,@VTWEG,@ZMD_UPID,@ZKUNNR_SP,@ZKUNNR_SH,@NAME3,@TELF1,@MOB_NUMBER,@TELFX,@SMTP_ADDR,@STRAS,@POST_CODE1,@CITY_CODE,@ZDATE_CR,@ZSTATUS,@ZDATE_DE,@ZREC_STA,@DATUM,@UZEIT,@UNAME,@DATUM_CR,@UZEIT_CR,@UNAME_CR,@DATUM_QY,@FLAG_QY,@ZMD_ATTR2,@ZCITY_TYPE)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@MANDT", SqlDbType.Char,3),
					new SqlParameter("@VKORG", SqlDbType.Char,4),
					new SqlParameter("@WERKS", SqlDbType.Char,4),
					new SqlParameter("@KUNNR", SqlDbType.Char,10),
					new SqlParameter("@NUM", SqlDbType.Char,3),
					new SqlParameter("@KUNNR_SH", SqlDbType.Char,10),
					new SqlParameter("@ZMD_ID", SqlDbType.Char,5),
					new SqlParameter("@ZMD_MC", SqlDbType.Char,40),
					new SqlParameter("@ZMD_JC", SqlDbType.Char,20),
					new SqlParameter("@ZMD_TYPE", SqlDbType.Char,20),
					new SqlParameter("@ZMD_ATTR", SqlDbType.Char,20),
					new SqlParameter("@VTWEG", SqlDbType.Char,20),
					new SqlParameter("@ZMD_UPID", SqlDbType.Char,50),
					new SqlParameter("@ZKUNNR_SP", SqlDbType.Char,10),
					new SqlParameter("@ZKUNNR_SH", SqlDbType.Char,10),
					new SqlParameter("@NAME3", SqlDbType.Char,35),
					new SqlParameter("@TELF1", SqlDbType.Char,16),
					new SqlParameter("@MOB_NUMBER", SqlDbType.Char,30),
					new SqlParameter("@TELFX", SqlDbType.Char,31),
					new SqlParameter("@SMTP_ADDR", SqlDbType.Char,241),
					new SqlParameter("@STRAS", SqlDbType.Char,150),
					new SqlParameter("@POST_CODE1", SqlDbType.Char,10),
					new SqlParameter("@CITY_CODE", SqlDbType.Char,12),
					new SqlParameter("@ZDATE_CR", SqlDbType.VarChar,50),
					new SqlParameter("@ZSTATUS", SqlDbType.Char,1),
					new SqlParameter("@ZDATE_DE", SqlDbType.VarChar,50),
					new SqlParameter("@ZREC_STA", SqlDbType.Char,1),
					new SqlParameter("@DATUM", SqlDbType.VarChar,50),
					new SqlParameter("@UZEIT", SqlDbType.VarChar,50),
					new SqlParameter("@UNAME", SqlDbType.Char,12),
					new SqlParameter("@DATUM_CR", SqlDbType.VarChar,50),
					new SqlParameter("@UZEIT_CR", SqlDbType.VarChar,50),
					new SqlParameter("@UNAME_CR", SqlDbType.Char,1),
					new SqlParameter("@DATUM_QY", SqlDbType.VarChar,50),
					new SqlParameter("@FLAG_QY", SqlDbType.Char,1),
					new SqlParameter("@ZMD_ATTR2", SqlDbType.Char,2),
					new SqlParameter("@ZCITY_TYPE", SqlDbType.Char,2)};
            parameters[0].Value = model.MANDT;
            parameters[1].Value = model.VKORG;
            parameters[2].Value = model.WERKS;
            parameters[3].Value = model.KUNNR;
            parameters[4].Value = model.NUM;
            parameters[5].Value = model.KUNNR_SH;
            parameters[6].Value = model.ZMD_ID;
            parameters[7].Value = model.ZMD_MC;
            parameters[8].Value = model.ZMD_JC;
            parameters[9].Value = model.ZMD_TYPE;
            parameters[10].Value = model.ZMD_ATTR;
            parameters[11].Value = model.VTWEG;
            parameters[12].Value = model.ZMD_UPID;
            parameters[13].Value = model.ZKUNNR_SP;
            parameters[14].Value = model.ZKUNNR_SH;
            parameters[15].Value = model.NAME3;
            parameters[16].Value = model.TELF1;
            parameters[17].Value = model.MOB_NUMBER;
            parameters[18].Value = model.TELFX;
            parameters[19].Value = model.SMTP_ADDR;
            parameters[20].Value = model.STRAS;
            parameters[21].Value = model.POST_CODE1;
            parameters[22].Value = model.CITY_CODE;
            parameters[23].Value = model.ZDATE_CR;
            parameters[24].Value = model.ZSTATUS;
            parameters[25].Value = model.ZDATE_DE;
            parameters[26].Value = model.ZREC_STA;
            parameters[27].Value = model.DATUM;
            parameters[28].Value = model.UZEIT;
            parameters[29].Value = model.UNAME;
            parameters[30].Value = model.DATUM_CR;
            parameters[31].Value = model.UZEIT_CR;
            parameters[32].Value = model.UNAME_CR;
            parameters[33].Value = model.DATUM_QY;
            parameters[34].Value = model.FLAG_QY;
            parameters[35].Value = model.ZMD_ATTR2;
            parameters[36].Value = model.ZCITY_TYPE;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 门店删除一条数据
        /// </summary>
        public bool StoreDelete()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_STORE ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 客户增加一条数据
        /// </summary>
        public int CustomerAdd(Model.SAP_CUSTOMER model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SAP_CUSTOMER(");
            strSql.Append("CLIENT,TYPE,CREATED_AT,BPEXT,NAME_LAST,NAME_FIRST,NAME1_TEXT,ZTITLE,NICKNAME,NAMEMIDDLE,NAMCOUNTRY,REGION,TRANSPZONE,XSEX,BIRTHDT,JOBGR,BUPA_IDTYPE_PRS,IDNUMBER,PSTREET,CSTREET,POST_CODE1,CPOST_CODE1,TEL_NUMBER,MOB_NUMBER,SMTP_ADDR,QQ,MSN,CTEL_NUMBER,CMOB_NUMBER,CFAX_NUMBER,CSMTP_ADDR,RE_BPEXT,REG_DATE,LOGINNAME,LOGINPASS,DEPTID,EMPID,vkorg,dis_channel,division,ZC001,ZC002,ZC003,ZC004,ZC008,ZC005,ZC007,ZA001,ZA002,ZA003,ZA004,ZA005,ZA006,ZB002,ZB003,ZC009,ZC010,ZC011,ZC012,ZC013,ZC014,ZC015,ZC016,ZC017,ZC018,ZC019,ZC020,ZC021,ZC023,CRDATE,CRTIME,CRNAME,PARTNER,CHECK_FLAG,TRANSFLAG,ZTIER,ZCCUR_POINT,Z_POINT)");
            strSql.Append(" values (");
            strSql.Append("@CLIENT,@TYPE,@CREATED_AT,@BPEXT,@NAME_LAST,@NAME_FIRST,@NAME1_TEXT,@ZTITLE,@NICKNAME,@NAMEMIDDLE,@NAMCOUNTRY,@REGION,@TRANSPZONE,@XSEX,@BIRTHDT,@JOBGR,@BUPA_IDTYPE_PRS,@IDNUMBER,@PSTREET,@CSTREET,@POST_CODE1,@CPOST_CODE1,@TEL_NUMBER,@MOB_NUMBER,@SMTP_ADDR,@QQ,@MSN,@CTEL_NUMBER,@CMOB_NUMBER,@CFAX_NUMBER,@CSMTP_ADDR,@RE_BPEXT,@REG_DATE,@LOGINNAME,@LOGINPASS,@DEPTID,@EMPID,@vkorg,@dis_channel,@division,@ZC001,@ZC002,@ZC003,@ZC004,@ZC008,@ZC005,@ZC007,@ZA001,@ZA002,@ZA003,@ZA004,@ZA005,@ZA006,@ZB002,@ZB003,@ZC009,@ZC010,@ZC011,@ZC012,@ZC013,@ZC014,@ZC015,@ZC016,@ZC017,@ZC018,@ZC019,@ZC020,@ZC021,@ZC023,@CRDATE,@CRTIME,@CRNAME,@PARTNER,@CHECK_FLAG,@TRANSFLAG,@ZTIER,@ZCCUR_POINT,@Z_POINT)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@CLIENT", SqlDbType.VarChar,50),
					new SqlParameter("@TYPE", SqlDbType.VarChar,50),
					new SqlParameter("@CREATED_AT", SqlDbType.VarChar,50),
					new SqlParameter("@BPEXT", SqlDbType.VarChar,50),
					new SqlParameter("@NAME_LAST", SqlDbType.VarChar,50),
					new SqlParameter("@NAME_FIRST", SqlDbType.VarChar,50),
					new SqlParameter("@NAME1_TEXT", SqlDbType.VarChar,200),
					new SqlParameter("@ZTITLE", SqlDbType.VarChar,50),
					new SqlParameter("@NICKNAME", SqlDbType.VarChar,50),
					new SqlParameter("@NAMEMIDDLE", SqlDbType.VarChar,50),
					new SqlParameter("@NAMCOUNTRY", SqlDbType.VarChar,50),
					new SqlParameter("@REGION", SqlDbType.VarChar,50),
					new SqlParameter("@TRANSPZONE", SqlDbType.VarChar,50),
					new SqlParameter("@XSEX", SqlDbType.VarChar,50),
					new SqlParameter("@BIRTHDT", SqlDbType.VarChar,50),
					new SqlParameter("@JOBGR", SqlDbType.VarChar,50),
					new SqlParameter("@BUPA_IDTYPE_PRS", SqlDbType.VarChar,50),
					new SqlParameter("@IDNUMBER", SqlDbType.VarChar,300),
					new SqlParameter("@PSTREET", SqlDbType.VarChar,300),
					new SqlParameter("@CSTREET", SqlDbType.VarChar,300),
					new SqlParameter("@POST_CODE1", SqlDbType.VarChar,50),
					new SqlParameter("@CPOST_CODE1", SqlDbType.VarChar,50),
					new SqlParameter("@TEL_NUMBER", SqlDbType.VarChar,50),
					new SqlParameter("@MOB_NUMBER", SqlDbType.VarChar,50),
					new SqlParameter("@SMTP_ADDR", SqlDbType.VarChar,500),
					new SqlParameter("@QQ", SqlDbType.VarChar,50),
					new SqlParameter("@MSN", SqlDbType.VarChar,50),
					new SqlParameter("@CTEL_NUMBER", SqlDbType.VarChar,50),
					new SqlParameter("@CMOB_NUMBER", SqlDbType.VarChar,50),
					new SqlParameter("@CFAX_NUMBER", SqlDbType.VarChar,50),
					new SqlParameter("@CSMTP_ADDR", SqlDbType.VarChar,500),
					new SqlParameter("@RE_BPEXT", SqlDbType.VarChar,50),
					new SqlParameter("@REG_DATE", SqlDbType.VarChar,50),
					new SqlParameter("@LOGINNAME", SqlDbType.VarChar,50),
					new SqlParameter("@LOGINPASS", SqlDbType.VarChar,50),
					new SqlParameter("@DEPTID", SqlDbType.VarChar,50),
					new SqlParameter("@EMPID", SqlDbType.VarChar,50),
					new SqlParameter("@vkorg", SqlDbType.VarChar,50),
                    new SqlParameter("@dis_channel",SqlDbType.VarChar,50),
					new SqlParameter("@division", SqlDbType.VarChar,50),
					new SqlParameter("@ZC001", SqlDbType.VarChar,50),
					new SqlParameter("@ZC002", SqlDbType.VarChar,50),
					new SqlParameter("@ZC003", SqlDbType.VarChar,50),
					new SqlParameter("@ZC004", SqlDbType.VarChar,50),
					new SqlParameter("@ZC008", SqlDbType.VarChar,50),
					new SqlParameter("@ZC005", SqlDbType.VarChar,50),
					new SqlParameter("@ZC007", SqlDbType.VarChar,50),
					new SqlParameter("@ZA001", SqlDbType.VarChar,50),
					new SqlParameter("@ZA002", SqlDbType.VarChar,50),
					new SqlParameter("@ZA003", SqlDbType.VarChar,50),
					new SqlParameter("@ZA004", SqlDbType.VarChar,50),
					new SqlParameter("@ZA005", SqlDbType.VarChar,50),
					new SqlParameter("@ZA006", SqlDbType.VarChar,50),
					new SqlParameter("@ZB002", SqlDbType.VarChar,50),
					new SqlParameter("@ZB003", SqlDbType.VarChar,50),
					new SqlParameter("@ZC009", SqlDbType.VarChar,50),
					new SqlParameter("@ZC010", SqlDbType.VarChar,50),
					new SqlParameter("@ZC011", SqlDbType.VarChar,50),
					new SqlParameter("@ZC012", SqlDbType.VarChar,50),
					new SqlParameter("@ZC013", SqlDbType.VarChar,50),
					new SqlParameter("@ZC014", SqlDbType.VarChar,50),
					new SqlParameter("@ZC015", SqlDbType.VarChar,50),
					new SqlParameter("@ZC016", SqlDbType.VarChar,50),
					new SqlParameter("@ZC017", SqlDbType.VarChar,50),
					new SqlParameter("@ZC018", SqlDbType.VarChar,50),
					new SqlParameter("@ZC019", SqlDbType.VarChar,50),
					new SqlParameter("@ZC020", SqlDbType.VarChar,50),
                    new SqlParameter("@ZC021", SqlDbType.VarChar,50),
                    new SqlParameter("@ZC023", SqlDbType.VarChar,50),
					new SqlParameter("@CRDATE", SqlDbType.VarChar,50),
					new SqlParameter("@CRTIME", SqlDbType.VarChar,50),
					new SqlParameter("@CRNAME", SqlDbType.VarChar,50),
					new SqlParameter("@PARTNER", SqlDbType.VarChar,50),
					new SqlParameter("@CHECK_FLAG", SqlDbType.VarChar,50),
					new SqlParameter("@TRANSFLAG", SqlDbType.VarChar,50),
					new SqlParameter("@ZTIER", SqlDbType.VarChar,50),
					new SqlParameter("@ZCCUR_POINT", SqlDbType.VarChar,50),
					new SqlParameter("@Z_POINT", SqlDbType.VarChar,50)};
            parameters[0].Value = model.CLIENT;
            parameters[1].Value = model.TYPE;
            parameters[2].Value = model.CREATED_AT;
            parameters[3].Value = model.BPEXT;
            parameters[4].Value = model.NAME_LAST;
            parameters[5].Value = model.NAME_FIRST;
            parameters[6].Value = model.NAME1_TEXT;
            parameters[7].Value = model.ZTITLE;
            parameters[8].Value = model.NICKNAME;
            parameters[9].Value = model.NAMEMIDDLE;
            parameters[10].Value = model.NAMCOUNTRY;
            parameters[11].Value = model.REGION;
            parameters[12].Value = model.TRANSPZONE;
            parameters[13].Value = model.XSEX;
            parameters[14].Value = model.BIRTHDT;
            parameters[15].Value = model.JOBGR;
            parameters[16].Value = model.BUPA_IDTYPE_PRS;
            parameters[17].Value = model.IDNUMBER;
            parameters[18].Value = model.PSTREET;
            parameters[19].Value = model.CSTREET;
            parameters[20].Value = model.POST_CODE1;
            parameters[21].Value = model.CPOST_CODE1;
            parameters[22].Value = model.TEL_NUMBER;
            parameters[23].Value = model.MOB_NUMBER;
            parameters[24].Value = model.SMTP_ADDR;
            parameters[25].Value = model.QQ;
            parameters[26].Value = model.MSN;
            parameters[27].Value = model.CTEL_NUMBER;
            parameters[28].Value = model.CMOB_NUMBER;
            parameters[29].Value = model.CFAX_NUMBER;
            parameters[30].Value = model.CSMTP_ADDR;
            parameters[31].Value = model.RE_BPEXT;
            parameters[32].Value = model.REG_DATE;
            parameters[33].Value = model.LOGINNAME;
            parameters[34].Value = model.LOGINPASS;
            parameters[35].Value = model.DEPTID;
            parameters[36].Value = model.EMPID;
            parameters[37].Value = model.vkorg;
            parameters[38].Value = model.dis_channel;
            parameters[39].Value = model.division;
            parameters[40].Value = model.ZC001;
            parameters[41].Value = model.ZC002;
            parameters[42].Value = model.ZC003;
            parameters[43].Value = model.ZC004;
            parameters[44].Value = model.ZC008;
            parameters[45].Value = model.ZC005;
            parameters[46].Value = model.ZC007;
            parameters[47].Value = model.ZA001;
            parameters[48].Value = model.ZA002;
            parameters[49].Value = model.ZA003;
            parameters[50].Value = model.ZA004;
            parameters[51].Value = model.ZA005;
            parameters[52].Value = model.ZA006;
            parameters[53].Value = model.ZB002;
            parameters[54].Value = model.ZB003;
            parameters[55].Value = model.ZC009;
            parameters[56].Value = model.ZC010;
            parameters[57].Value = model.ZC011;
            parameters[58].Value = model.ZC012;
            parameters[59].Value = model.ZC013;
            parameters[60].Value = model.ZC014;
            parameters[61].Value = model.ZC015;
            parameters[62].Value = model.ZC016;
            parameters[63].Value = model.ZC017;
            parameters[64].Value = model.ZC018;
            parameters[65].Value = model.ZC019;
            parameters[66].Value = model.ZC020;
            parameters[67].Value = model.ZC021;
            parameters[68].Value = model.ZC023;
            parameters[69].Value = model.CRDATE;
            parameters[70].Value = model.CRTIME;
            parameters[71].Value = model.CRNAME;
            parameters[72].Value = model.PARTNER;
            parameters[73].Value = model.CHECK_FLAG;
            parameters[74].Value = model.TRANSFLAG;
            parameters[75].Value = model.ZTIER;
            parameters[76].Value = model.ZCCUR_POINT;
            parameters[77].Value = model.Z_POINT;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 客户删除一条数据
        /// </summary>
        public bool CustomerDelete()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SAP_CUSTOMER ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
